/**
*@Author      ：anlzou
*@Date        ：21:32 2021/4/23
*@Github      ：https://github.com/anlzou
*@Description ：
*/
package com.anlzou.bank;

import java.util.concurrent.atomic.AtomicInteger;

public class SyncAtomicIntegerBank extends Bank{
    private AtomicInteger count = new AtomicInteger(100);

    // 存钱
    public void addMoney(int money) {
        count.addAndGet(money);
        System.out.println(System.currentTimeMillis()+"存进："+money);
    }

    // 取钱
    public void subMoney(int money){
        if(count.get()-money < 0){
            System.out.println("余额不足");
            return;
        }
        count.addAndGet(-money);
        System.out.println(+System.currentTimeMillis()+"取出："+money);
    }

    //查询
    public void lookMoney(){
        System.out.println("账户余额："+count);
    }
}
